import numpy as np
import cv2 as cv
import logging as log
import logistic.logsiticmethod as logistic

import Process.processmethod as process
def main():
    cap = cv.VideoCapture(0)
    while True:
        ret, frame = cap.read()
        frame = cv.convertScaleAbs(frame)
        log.info("成功获得帧")
        frame,facelocation=process.detect_face(frame)

        #获得特征值
        process.getencodings(frame, facelocation)

        mask = process.create_mask(frame, facelocation)
        size = np.sum(mask == 255)
        print(f"非人脸区域的像素数量: {size}")
        key = logistic.generate_chaotic_sequence(size,3.9,0.5)
        print(f"生成的混沌序列长度: {len(key)}")
        frame = logistic.encrypt_region(frame,mask,key)
        cv.imshow('img', frame)
        if cv.waitKey(1) & 0xFF == ord('q'):
            break

if __name__ == "__main__":
        main()





